package com.sizu.web;

import com.alipay.api.AlipayApiException;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.sizu.entity.*;
import com.sizu.service.*;
import com.zhaoyuxi.qrcode.service.AlibabapayQrCodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/back")
@Slf4j
public class BackDownController {

    @Autowired
    private ITPurchaseListService itPurchaseListService;

    @Autowired
    private ITReturnListService itReturnListService;

    @Autowired
    private ITSaleListService itSaleListService;

    @Autowired
    private ITCustomerReturnListService itCustomerReturnListService;

    @Autowired
    private ITCustomerStatementService itCustomerStatementService;

    @Autowired
    private ITSupplierStatementService itSupplierStatementService;

    @Autowired
    private AlibabapayQrCodeService alibabapayQrCodeService;

    @RequestMapping("/reslove")
    public void backReslove() throws AlipayApiException {
        List<TPurchaseList> tPurchaseList = itPurchaseListService.getTPurchaseList();
        for (TPurchaseList purchaseList : tPurchaseList) {
            String str = purchaseList.getPurchaseNumber().replace("JH", "99");
            boolean qrCodePayOrder = alibabapayQrCodeService.getQrCodePayOrder(str);
            if (qrCodePayOrder) {
                itPurchaseListService.upTPurchaseListState(purchaseList.getPurchaseNumber());
            }
        }
        List<TReturnList> tReturnList = itReturnListService.getTReturnList();
        for (TReturnList returnList : tReturnList) {
            String str = returnList.getReturnNumber().replace("TH", "88");
            boolean qrCodePayOrder = alibabapayQrCodeService.getQrCodePayOrder(str);
            if (qrCodePayOrder) {
                itReturnListService.upTReturnListState(returnList.getReturnNumber());
            }
        }
        List<TSaleList> tSaleList = itSaleListService.getTSaleList();
        for (TSaleList saleList : tSaleList) {
            String str = saleList.getSaleNumber().replace("XS", "77");
            boolean qrCodePayOrder = alibabapayQrCodeService.getQrCodePayOrder(str);
            if (qrCodePayOrder) {
                itSaleListService.upTSaleListState(saleList.getSaleNumber());
            }
        }
        List<TCustomerReturnList> tCustomerReturnList = itCustomerReturnListService.getTCustomerReturnList();
        for (TCustomerReturnList customerReturnList : tCustomerReturnList) {
            String str = customerReturnList.getCustomerReturnNumber().replace("XT", "66");
            boolean qrCodePayOrder = alibabapayQrCodeService.getQrCodePayOrder(str);
            if (qrCodePayOrder) {
                itCustomerReturnListService.upTCustomerReturnListState(customerReturnList.getCustomerReturnNumber());
            }
        }
        List<TSupplierStatement> tSupplierStatement = itSupplierStatementService.getTSupplierStatement();
        for (TSupplierStatement supplierStatement : tSupplierStatement) {
            String str = supplierStatement.getSupplierNumber();
            str = str.replace("JH", "99");
            str = str.replace("TH", "88");
            boolean qrCodePayOrder = alibabapayQrCodeService.getQrCodePayOrder(str);
            if (qrCodePayOrder) {
                itSupplierStatementService.upTSupplierStatementState(supplierStatement.getSupplierNumber());
            }
        }
        List<TCustomerStatement> tCustomerStatement = itCustomerStatementService.getTCustomerStatement();
        for (TCustomerStatement customerStatement : tCustomerStatement) {
            String str = customerStatement.getCustomerNumber();
            str = str.replace("XS", "77");
            str = str.replace("XT", "66");
            boolean qrCodePayOrder = alibabapayQrCodeService.getQrCodePayOrder(str);
            if (qrCodePayOrder) {
                itCustomerStatementService.upTCustomerStatementState(customerStatement.getCustomerNumber());
            }
        }
    }

}
